package com.huike.report.mapper;

import com.github.pagehelper.Page;
import com.huike.clues.domain.TbActivity;
import com.huike.report.domain.Index;
import com.huike.report.domain.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 首页统计分析的Mapper
 * @author Administrator
 *
 */
@Mapper
public interface ReportMapper {
    /**=========================================基本数据========================================*/

    Integer countClues(Index index);


    Integer countBusiness(Index index);

    Integer countContractByTime(Index index);

    Double sumBusinessByTime(Index index);

    Integer countClueOrBusinessByAssign(Index index);

    @Select("select dept_id from sys_user where user_id = #{userId}")
    Integer selectDeptId(String userId);

    @Select("select dept_name from sys_dept where dept_id = #{deptId}")
    String selectDeptName(Integer deptId);

    @Select("select distinct create_by from tb_business ")
    List<String> selectNameOfBusiness();


    /**=========================================基本数据========================================*/

    Integer NewDaySelect(@Param("beginCreateTime") String beginCreateTime,@Param("endCreateTime")String endCreateTime);

    Integer OrderDaySelect(String date);

    Page<ClueVo>  CountSelect(@Param("beginCreateTime") String beginCreateTime, @Param("endCreateTime")String endCreateTime);

    /**=========================================基本数据========================================*/
    Page<DeptContractVO> deptStatisticsList(@Param("begin") LocalDateTime beginTime,@Param("end") LocalDateTime endTime);

    Page<OwnerVO> ownerShipStatisticsList(@Param("begin") LocalDateTime beginTime,@Param("end") LocalDateTime endTime);

    Page<ChannelVO> channelStatisticsList(@Param("begin") LocalDateTime beginTime,@Param("end") LocalDateTime endTime);


    /**=========================================基本数据========================================*/

    List<TbActivity> getActivityStatisticsList(TbActivity tbActivity);

    List<ChanelStatisticsVo> chanelStatistics(@Param("beginCreateTime") String beginCreateTime,@Param("endCreateTime") String endCreateTime);

    /**
     * 根据id查询活动
     * @param activityId
     * @return
     */
    @Select("select * from tb_activity where id = #{activityId}")
    TbActivity getByActivityId(Long activityId);

    @Select("select distinct us.user_id\n" +
            "from tb_clue c\n" +
            "    left join tb_assign_record ar on c.id = ar.assign_id and ar.type = 0\n" +
            "     left join sys_user us on ar.user_id = us.user_id")
    List<String> selectUserIdOfClue();

    @Select("select nick_name from sys_user where user_id = #{userId}")
    String selectNameByUserId(String userId);

    @Select("select count(*)\n" +
            "from tb_clue c\n" +
            "    left join tb_assign_record ar on c.id = ar.assign_id and ar.type = 0\n" +
            "     left join sys_user us on ar.user_id = us.user_id where c.status = 6 and us.user_id = #{userId}")
    Integer countCluesByUserId(String userId);

    @Select("select distinct us.user_id\n" +
            "from tb_business b\n" +
            "    left join tb_assign_record ar on b.id = ar.assign_id and ar.type = 1\n" +
            "     left join sys_user us on ar.user_id = us.user_id")
    List<String> selectUserIdOfBusiness();

    @Select("select count(*)\n" +
            "from tb_business b\n" +
            "    left join tb_assign_record ar on b.id = ar.assign_id and ar.type = 1\n" +
            "     left join sys_user us on ar.user_id = us.user_id where b.status = 7 and us.user_id = #{userId}")
    Integer countBusinessByUserId(String userId);


    /**=========================================今日简报========================================*/



	/**=========================================待办========================================*/

}
